from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-17 14:16:34.040923
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 17, Oct, 2022
Time: 14:16:42
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.7377
Nobs: 812.000 HQIC: -51.0587
Log likelihood: 10531.4 FPE: 5.47861e-23
AIC: -51.2586 Det(Omega_mle): 4.90714e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.295534 0.052452 5.634 0.000
L1.Burgenland 0.109134 0.035323 3.090 0.002
L1.Kärnten -0.106445 0.018809 -5.659 0.000
L1.Niederösterreich 0.210523 0.073877 2.850 0.004
L1.Oberösterreich 0.099556 0.070870 1.405 0.160
L1.Salzburg 0.250857 0.037624 6.668 0.000
L1.Steiermark 0.038624 0.049257 0.784 0.433
L1.Tirol 0.106435 0.039947 2.664 0.008
L1.Vorarlberg -0.058943 0.034348 -1.716 0.086
L1.Wien 0.059205 0.063191 0.937 0.349
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063149 0.108572 0.582 0.561
L1.Burgenland -0.033622 0.073115 -0.460 0.646
L1.Kärnten 0.047760 0.038933 1.227 0.220
L1.Niederösterreich -0.172285 0.152920 -1.127 0.260
L1.Oberösterreich 0.385046 0.146695 2.625 0.009
L1.Salzburg 0.286748 0.077879 3.682 0.000
L1.Steiermark 0.105861 0.101958 1.038 0.299
L1.Tirol 0.313657 0.082687 3.793 0.000
L1.Vorarlberg 0.025365 0.071098 0.357 0.721
L1.Wien -0.015066 0.130800 -0.115 0.908
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189801 0.026927 7.049 0.000
L1.Burgenland 0.090210 0.018134 4.975 0.000
L1.Kärnten -0.008439 0.009656 -0.874 0.382
L1.Niederösterreich 0.264580 0.037926 6.976 0.000
L1.Oberösterreich 0.126420 0.036382 3.475 0.001
L1.Salzburg 0.047940 0.019315 2.482 0.013
L1.Steiermark 0.017115 0.025287 0.677 0.499
L1.Tirol 0.094393 0.020507 4.603 0.000
L1.Vorarlberg 0.059312 0.017633 3.364 0.001
L1.Wien 0.119701 0.032440 3.690 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109762 0.027591 3.978 0.000
L1.Burgenland 0.044276 0.018580 2.383 0.017
L1.Kärnten -0.016115 0.009894 -1.629 0.103
L1.Niederösterreich 0.192953 0.038861 4.965 0.000
L1.Oberösterreich 0.294093 0.037279 7.889 0.000
L1.Salzburg 0.115296 0.019791 5.826 0.000
L1.Steiermark 0.099668 0.025910 3.847 0.000
L1.Tirol 0.116376 0.021013 5.538 0.000
L1.Vorarlberg 0.070656 0.018068 3.911 0.000
L1.Wien -0.027368 0.033239 -0.823 0.410
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127271 0.050082 2.541 0.011
L1.Burgenland -0.051600 0.033727 -1.530 0.126
L1.Kärnten -0.040466 0.017959 -2.253 0.024
L1.Niederösterreich 0.169631 0.070539 2.405 0.016
L1.Oberösterreich 0.137232 0.067667 2.028 0.043
L1.Salzburg 0.285023 0.035924 7.934 0.000
L1.Steiermark 0.034408 0.047031 0.732 0.464
L1.Tirol 0.164835 0.038142 4.322 0.000
L1.Vorarlberg 0.104224 0.032796 3.178 0.001
L1.Wien 0.071604 0.060335 1.187 0.235
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060674 0.039688 1.529 0.126
L1.Burgenland 0.038751 0.026727 1.450 0.147
L1.Kärnten 0.050768 0.014232 3.567 0.000
L1.Niederösterreich 0.225536 0.055899 4.035 0.000
L1.Oberösterreich 0.282523 0.053623 5.269 0.000
L1.Salzburg 0.051277 0.028468 1.801 0.072
L1.Steiermark -0.007768 0.037270 -0.208 0.835
L1.Tirol 0.149422 0.030225 4.944 0.000
L1.Vorarlberg 0.070899 0.025989 2.728 0.006
L1.Wien 0.078908 0.047813 1.650 0.099
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.177128 0.047427 3.735 0.000
L1.Burgenland -0.005798 0.031939 -0.182 0.856
L1.Kärnten -0.061200 0.017007 -3.598 0.000
L1.Niederösterreich -0.083891 0.066800 -1.256 0.209
L1.Oberösterreich 0.192025 0.064080 2.997 0.003
L1.Salzburg 0.057350 0.034019 1.686 0.092
L1.Steiermark 0.230409 0.044538 5.173 0.000
L1.Tirol 0.494342 0.036120 13.686 0.000
L1.Vorarlberg 0.049620 0.031058 1.598 0.110
L1.Wien -0.047797 0.057137 -0.837 0.403
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162118 0.054448 2.977 0.003
L1.Burgenland -0.011379 0.036667 -0.310 0.756
L1.Kärnten 0.065903 0.019525 3.375 0.001
L1.Niederösterreich 0.200367 0.076688 2.613 0.009
L1.Oberösterreich -0.061063 0.073566 -0.830 0.407
L1.Salzburg 0.216512 0.039055 5.544 0.000
L1.Steiermark 0.113626 0.051131 2.222 0.026
L1.Tirol 0.077246 0.041467 1.863 0.062
L1.Vorarlberg 0.124545 0.035655 3.493 0.000
L1.Wien 0.114170 0.065595 1.741 0.082
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.353356 0.031732 11.136 0.000
L1.Burgenland 0.005758 0.021369 0.269 0.788
L1.Kärnten -0.023610 0.011379 -2.075 0.038
L1.Niederösterreich 0.223951 0.044693 5.011 0.000
L1.Oberösterreich 0.175111 0.042874 4.084 0.000
L1.Salzburg 0.047544 0.022761 2.089 0.037
L1.Steiermark -0.016627 0.029799 -0.558 0.577
L1.Tirol 0.109042 0.024166 4.512 0.000
L1.Vorarlberg 0.073769 0.020780 3.550 0.000
L1.Wien 0.052922 0.038228 1.384 0.166
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041245 0.152592 0.190061 0.157377 0.124285 0.113897 0.065568 0.226917
Kärnten 0.041245 1.000000 -0.002641 0.129788 0.041482 0.095939 0.429482 -0.053124 0.101141
Niederösterreich 0.152592 -0.002641 1.000000 0.336889 0.154397 0.300300 0.111117 0.183810 0.328005
Oberösterreich 0.190061 0.129788 0.336889 1.000000 0.232077 0.332493 0.172700 0.172497 0.262712
Salzburg 0.157377 0.041482 0.154397 0.232077 1.000000 0.145934 0.127155 0.148898 0.134168
Steiermark 0.124285 0.095939 0.300300 0.332493 0.145934 1.000000 0.153399 0.140878 0.078882
Tirol 0.113897 0.429482 0.111117 0.172700 0.127155 0.153399 1.000000 0.115026 0.154993
Vorarlberg 0.065568 -0.053124 0.183810 0.172497 0.148898 0.140878 0.115026 1.000000 0.007200
Wien 0.226917 0.101141 0.328005 0.262712 0.134168 0.078882 0.154993 0.007200 1.000000